package com.wish233.wiliwilisearch.domain.esdto;

import cn.hutool.core.bean.BeanUtil;
import com.wish233.wiliwiliapi.domain.vo.VideoVO;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;

import java.util.Date;

/**
 * @author WHH
 */
@Data
@Document(indexName = "wiliwili_video")
@Setting(settingPath = "es-settings.json")
public class VideoEsDTO {

    private static final String DATE_TIME_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
    /**
     * 视频ID（主键）
     */
    @Id
    private Long id;

    /**
     * 视频标题
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String title;

    /**
     * 视频简介
     */
    @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart")
    private String description;

    /**
     * 点赞数
     */
    private Integer likes;

    /**
     * 评论数
     */
    private Integer comments;

    /**
     * 视频URL
     */
    private String url;

    /**
     * 视频封面URL
     */
    private String coverUrl;

    /**
     * 视频时长（秒）
     */
    private Integer duration;

    /**
     * 上传者ID
     */
    private Long author;

    /**
     * 视频分类ID
     */
    private Long categoryId;

    /**
     * 视频状态（0:审核中, 1:已发布, 2:已下架）
     */
    private Integer status;

    /**
     * 播放次数
     */
    private Long viewCount;

    /**
     * 是否删除（0:未删除, 1:已删除）
     */
    private Integer isDelete;

    /**
     * 创建时间
     */
    @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN)
    private Date createTime;

    /**
     * 更新时间
     */
    @Field(index = false, store = true, type = FieldType.Date, format = {}, pattern = DATE_TIME_PATTERN)
    private Date updateTime;

    /**
     * 标签 json字符串
     */
    private String tags;

    public static VideoVO esDTO2VO(VideoEsDTO videoEsDTO) {
        if (videoEsDTO == null) {
            return null;
        }
        return BeanUtil.copyProperties(videoEsDTO, VideoVO.class);
    }

    public static VideoEsDTO vo2EsDTO(VideoVO videoVO) {
        if (videoVO == null) {
            return null;
        }
        return BeanUtil.copyProperties(videoVO, VideoEsDTO.class);
    }

}
